<!DOCTYPE html>


<html lang="zh-CN">


<head>
  <meta charset="utf-8" />
    
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <title>
    推荐这款开源、轻量无 Agent 自动化运维平台.md |  
  </title>
  <meta name="generator" content="hexo-theme-ayer">
  
  <link rel="shortcut icon" href="/favicon.ico" />
  
  
<link rel="stylesheet" href="/dist/main.css">

  
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Shen-Yu/cdn/css/remixicon.min.css">

  
<link rel="stylesheet" href="/css/custom.css">

  
  
<script src="https://cdn.jsdelivr.net/npm/pace-js@1.0.2/pace.min.js"></script>

  
  

  

</head>

</html>

<body>
  <div id="app">
    
      
    <main class="content on">
      <section class="outer">
  <article
  id="post-develop/推荐这款开源、轻量无 Agent 自动化运维平台"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h1 class="article-title sea-center" style="border-left:0" itemprop="name">
  推荐这款开源、轻量无 Agent 自动化运维平台.md
</h1>
 

    </header>
     
    <div class="article-meta">
      <a href="/2020/11/11/develop/%E6%8E%A8%E8%8D%90%E8%BF%99%E6%AC%BE%E5%BC%80%E6%BA%90%E3%80%81%E8%BD%BB%E9%87%8F%E6%97%A0%20Agent%20%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E5%B9%B3%E5%8F%B0/" class="article-date">
  <time datetime="2020-11-10T16:00:00.000Z" itemprop="datePublished">2020-11-11</time>
</a> 
  <div class="article-category">
    <a class="article-category-link" href="/categories/develop/">develop</a>
  </div>
  
<div class="word_count">
    <span class="post-time">
        <span class="post-meta-item-icon">
            <i class="ri-quill-pen-line"></i>
            <span class="post-meta-item-text"> 字数统计:</span>
            <span class="post-count">1.9k</span>
        </span>
    </span>

    <span class="post-time">
        &nbsp; | &nbsp;
        <span class="post-meta-item-icon">
            <i class="ri-book-open-line"></i>
            <span class="post-meta-item-text"> 阅读时长≈</span>
            <span class="post-count">7 分钟</span>
        </span>
    </span>
</div>
 
    </div>
      
    <div class="tocbot"></div>




  
    <div class="article-entry" itemprop="articleBody">
       
  <h1 id="推荐这款开源、轻量无-Agent-自动化运维平台"><a href="#推荐这款开源、轻量无-Agent-自动化运维平台" class="headerlink" title="推荐这款开源、轻量无 Agent 自动化运维平台"></a>推荐这款开源、轻量无 Agent 自动化运维平台</h1><p>在日常运维管理的发展过程中，可视化、自动化是一个阶段的进程必备要素，所以，对于可视化运维平台的掌握与了解也非常重要，我们运维小伙伴们也在不断的探索与挖掘当中，今天，民工哥给大家安利一款可视化的自动化运维管理平台：Spug，开源、免费，功能强大。</p>
<h2 id="Spug简介"><a href="#Spug简介" class="headerlink" title="Spug简介"></a>Spug简介</h2><p>Spug面向中小型企业设计的轻量级无 Agent 的自动化运维平台，整合了主机管理、主机批量执行、主机在线终端、文件在线上传下载、应用发布部署、在线任务计划、配置中心、监控、报警等一系列功能。</p>
<ul>
<li>代码仓库地址：<a target="_blank" rel="noopener" href="https://github.com/openspug/spug.dev">https://github.com/openspug/spug.dev</a></li>
<li>官网地址：<a target="_blank" rel="noopener" href="https://www.spug.dev/">https://www.spug.dev</a></li>
<li>使用文档：<a target="_blank" rel="noopener" href="https://www.spug.dev/docs/about-spug/">https://www.spug.dev/docs/about-spug/</a></li>
<li>更新日志：<a target="_blank" rel="noopener" href="https://www.spug.dev/docs/change-log/">https://www.spug.dev/docs/change-log/</a></li>
<li>常见问题：<a target="_blank" rel="noopener" href="https://www.spug.dev/docs/faq/">https://www.spug.dev/docs/faq/</a></li>
</ul>
<h2 id="Spug的功能"><a href="#Spug的功能" class="headerlink" title="Spug的功能"></a>Spug的功能</h2><ul>
<li>批量执行: 主机命令在线批量执行</li>
<li>在线终端: 主机支持浏览器在线终端登录</li>
<li>文件管理: 主机文件在线上传下载</li>
<li>任务计划: 灵活的在线任务计划</li>
<li>发布部署: 支持自定义发布部署流程</li>
<li>配置中心: 支持 KV、文本、json 等格式的配置</li>
<li>监控中心: 支持站点、端口、进程、自定义等监控</li>
<li>报警中心: 支持短信、邮件、钉钉、微信等报警方式</li>
<li>优雅美观: 基于 Ant Design 的 UI 界面</li>
<li>开源免费: 前后端代码完全开源</li>
</ul>
<h2 id="安装环境要求"><a href="#安装环境要求" class="headerlink" title="安装环境要求"></a>安装环境要求</h2><ul>
<li>Python 3.6+</li>
<li>Django 2.2</li>
<li>Node 12.14</li>
<li>React 16.11</li>
</ul>
<h2 id="安装Spug"><a href="#安装Spug" class="headerlink" title="安装Spug"></a>安装Spug</h2><p>简化一切安装操作步骤，官方也建议使用docker进行安装，那么，接下来就使用docker来安装这款工具平台。本文操作基于Centos7.x操作系统。</p>
<p><strong>1. 安装docker并启动</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">yum install docker -y</span><br><span class="line">systemctl start docker</span><br></pre></td></tr></table></figure>

<p><strong>2. 拉取镜像</strong></p>
<p>阿里云的镜像与 Docker hub 同步更新，国内用户建议使用阿里云的镜像。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ docker pull registry.aliyuncs.com&#x2F;openspug&#x2F;spug</span><br></pre></td></tr></table></figure>

<p><strong>3. 启动容器</strong></p>
<p>Docker镜像内部使用的 Mysql 数据库。如果需要持久化存储代码和数据，可以添加：-v 映射容器内/data路径</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">$ docker run -d --name&#x3D;spug -p 80:80 registry.aliyuncs.com&#x2F;openspug&#x2F;spug</span><br><span class="line"></span><br><span class="line"># 持久化存储启动命令：</span><br><span class="line"># mydata是本地磁盘路径，&#x2F;data是容器内代码和数据初始化存储的路径</span><br><span class="line">$ docker run -d --name&#x3D;spug -p 80:80 -v &#x2F;mydata&#x2F;:&#x2F;data registry.aliyuncs.com&#x2F;openspug&#x2F;spug</span><br></pre></td></tr></table></figure>

<p><strong>4. 初始化</strong></p>
<p>以下操作会创建一个用户名为 admin 密码为 spug.dev 的管理员账户，可自行替换管理员账户。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">$ docker exec spug init_spug admin spug.dev</span><br><span class="line"></span><br><span class="line"># 执行完毕后需要重启容器</span><br><span class="line">$ docker restart spug</span><br></pre></td></tr></table></figure>

<p><strong>5. 访问测试</strong></p>
<p>在浏览器中输入 <a target="_blank" rel="noopener" href="http://localhost/">http://localhost:80</a> 访问,用户名：admin  密码：spug.dev</p>
<p><img src="http://iubest.gitee.io/pic/640-1601003929840.webp" alt="img"></p>
<h2 id="使用介绍"><a href="#使用介绍" class="headerlink" title="使用介绍"></a>使用介绍</h2><p>登录完成后，就可以看到主界面，如下</p>
<p><img src="http://iubest.gitee.io/pic/640-1601003929908.webp" alt="img"></p>
<p><strong>主机管理</strong></p>
<p>管理维护平台可操作的主机，首次添加主机时需要输入 ssh 指定用户的密码。</p>
<p><img src="http://iubest.gitee.io/pic/640-1601003929906.webp" alt="img"></p>
<p><strong>批量执行</strong></p>
<p>包含维护命令模版和批量远程执行命令两部分功能，常用来执行一些临时的任务例如，批量安装/卸载某个依赖包等。</p>
<p><img src="http://iubest.gitee.io/pic/640-1601003929745.webp" alt="img"></p>
<ul>
<li>执行任务</li>
</ul>
<p>可以选择一到多个在主机管理中添加的主机作为执行的目标主机，命令内容可以直接写也支持从模板中读取已保存的命令。</p>
<ul>
<li>模板管理</li>
</ul>
<p>用于存储复杂、常用的命令集合，以便后期可随时使用。</p>
<p><strong>应用发布</strong></p>
<ul>
<li>应用管理</li>
</ul>
<p>管理和维护可发布的应用。每个应用又可以创建对应环境的发布配置，发布配置请查看发布配置文档。</p>
<p><img src="http://iubest.gitee.io/pic/640-1601003929710.webp" alt="img"></p>
<ul>
<li>发布配置</li>
</ul>
<p>配置指定应用在某环境下如何执行发布，发布支持两种方式 常规发布 和 自定义发布。</p>
<ul>
<li>发布申请</li>
</ul>
<p>创建和执行发布。</p>
<p><img src="http://iubest.gitee.io/pic/640-1601366764736.webp" alt="img"></p>
<p><strong>配置中心</strong></p>
<ul>
<li>环境管理</li>
</ul>
<p>管理应用的运行环境，一般包含开发环境、测试环境和生产环境，应用发布和配置管理需要用它来区分不同的环境。</p>
<p><img src="http://iubest.gitee.io/pic/640-1601003929907.png" alt="img"></p>
<ul>
<li>服务管理</li>
</ul>
<p>管理和维护应用依赖的服务配置。例如有两个应用 A 和应用 B，它们共同使用一个数据库，那么就可以把这个数据库提取出来作为单独的服务来管理。这样带来的好处是如果这个数据库配置变更了，那么只需要在服务管理里把这个数据库的配置更新即可，不必在多个应用之间切换查找更新。</p>
<p><img src="http://iubest.gitee.io/pic/640-1601003929824.webp" alt="img"></p>
<ul>
<li>应用管理</li>
</ul>
<p>用于维护应用的配置，应用配置包含 公共 和 私有 两种类型的配置。</p>
<ul>
<li>配置管理</li>
</ul>
<p>用户维护服务和应用在不同环境下的具体配置。</p>
<p><strong>任务调度</strong></p>
<p>维护一些周期性的任务</p>
<p><img src="http://iubest.gitee.io/pic/640-1601003929829.webp" alt="img"></p>
<p><strong>监控中心</strong></p>
<p>该模块提供了以下几种常用的监控模式</p>
<ul>
<li>站点检测</li>
</ul>
<p>通过 GET 请求指定的 url 匹配返回的状态码来确定站点是否异常</p>
<ul>
<li>端口检测</li>
</ul>
<p>检测指定目标主机的端口是否可以正常建立接连</p>
<ul>
<li>进程检测</li>
</ul>
<p>检测指定目标主机的某个进程是否存活</p>
<ul>
<li>自定义脚本检测</li>
</ul>
<p>在指定主机上运行自定义的脚本，通过判断返回的退出状态码来确定是否有异常</p>
<p><img src="http://iubest.gitee.io/pic/640-1601003929902.png" alt="img"></p>
<p><strong>报警中心</strong></p>
<p>配置与维护日常报警相关，如:报警记录、报警联系人与组</p>
<p><img src="http://iubest.gitee.io/pic/640-1601003929909.webp" alt="img"></p>
<p><strong>系统管理</strong></p>
<p>除了页面上对普通用的管理，Spug 还提供了 manage.py user 命令可用于管理员账户的管理操作。</p>
<ul>
<li>创建账户</li>
</ul>
<p>创建账户使用 manage.py user add 命令，用法示例如下</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">$ cd spug&#x2F;spug_api</span><br><span class="line">$ source venv&#x2F;bin&#x2F;activate</span><br><span class="line">$ python manage.py user add -u admin -p 123 -n 民工哥 -s</span><br></pre></td></tr></table></figure>

<p>Docker 安装的可以执行如下命令</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$ docker exec spug python3 &#x2F;data&#x2F;spug&#x2F;spug_api&#x2F;manage.py user add -u admin -p 123 -n 民工哥 -s</span><br><span class="line">#上面的命令会创建个登录名为 admin 密码为 123 昵称为 民工哥 的管理员账户，注意最后的 -s 参数，如果携带了这个参数意味着该账户为管理员账户， 管理员账户可以不受任何限制的访问所有功能模块。</span><br></pre></td></tr></table></figure>

<ul>
<li>重置密码</li>
</ul>
<p>使用 manage.py user reset 命令来重置账户密码，用法示例如下</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">$ cd spug&#x2F;spug_api</span><br><span class="line">$ source venv&#x2F;bin&#x2F;activate</span><br><span class="line">$ python manage.py user reset -u admin -p abc</span><br></pre></td></tr></table></figure>

<p>Docker 安装的可以执行如下命令</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$ docker exec spug python3 &#x2F;data&#x2F;spug&#x2F;spug_api&#x2F;manage.py user reset -u admin -p abc</span><br><span class="line">#上述操作会重置登录名为 admin 的账户的密码为 abc。</span><br></pre></td></tr></table></figure>

<ul>
<li>启用账户</li>
</ul>
<p>当页面上登录连续错误数次超过3次后账户自动转为禁用状态，普通用户可以通过 系统管理 / 账户管理 在页面是启用账户即可，但管理员账户需要使用如下命令来启用</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">$ cd spug&#x2F;spug_api</span><br><span class="line">$ source venv&#x2F;bin&#x2F;activate</span><br><span class="line">$ python manage.py user enable -u admin</span><br></pre></td></tr></table></figure>

<p>Docker 安装的可以执行如下命令</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ docker exec spug python3 &#x2F;data&#x2F;spug&#x2F;spug_api&#x2F;manage.py user enable -u admin</span><br></pre></td></tr></table></figure> 
      <!-- reward -->
      
      <div id="reword-out">
        <div id="reward-btn">
          打赏
        </div>
      </div>
      
    </div>
    

    <!-- copyright -->
    
    <div class="declare">
      <ul class="post-copyright">
        <li>
          <i class="ri-copyright-line"></i>
          <strong>版权声明： </strong>
          
          本博客所有文章除特别声明外，著作权归作者所有。转载请注明出处！
          
        </li>
      </ul>
    </div>
    
    <footer class="article-footer">
       
<div class="share-btn">
      <span class="share-sns share-outer">
        <i class="ri-share-forward-line"></i>
        分享
      </span>
      <div class="share-wrap">
        <i class="arrow"></i>
        <div class="share-icons">
          
          <a class="weibo share-sns" href="javascript:;" data-type="weibo">
            <i class="ri-weibo-fill"></i>
          </a>
          <a class="weixin share-sns wxFab" href="javascript:;" data-type="weixin">
            <i class="ri-wechat-fill"></i>
          </a>
          <a class="qq share-sns" href="javascript:;" data-type="qq">
            <i class="ri-qq-fill"></i>
          </a>
          <a class="douban share-sns" href="javascript:;" data-type="douban">
            <i class="ri-douban-line"></i>
          </a>
          <!-- <a class="qzone share-sns" href="javascript:;" data-type="qzone">
            <i class="icon icon-qzone"></i>
          </a> -->
          
          <a class="facebook share-sns" href="javascript:;" data-type="facebook">
            <i class="ri-facebook-circle-fill"></i>
          </a>
          <a class="twitter share-sns" href="javascript:;" data-type="twitter">
            <i class="ri-twitter-fill"></i>
          </a>
          <a class="google share-sns" href="javascript:;" data-type="google">
            <i class="ri-google-fill"></i>
          </a>
        </div>
      </div>
</div>

<div class="wx-share-modal">
    <a class="modal-close" href="javascript:;"><i class="ri-close-circle-line"></i></a>
    <p>扫一扫，分享到微信</p>
    <div class="wx-qrcode">
      <img src="//api.qrserver.com/v1/create-qr-code/?size=150x150&data=http://example.com/2020/11/11/develop/%E6%8E%A8%E8%8D%90%E8%BF%99%E6%AC%BE%E5%BC%80%E6%BA%90%E3%80%81%E8%BD%BB%E9%87%8F%E6%97%A0%20Agent%20%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E5%B9%B3%E5%8F%B0/" alt="微信分享二维码">
    </div>
</div>

<div id="share-mask"></div>  
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/develop/" rel="tag">develop</a></li></ul>

    </footer>
  </div>

   
  <nav class="article-nav">
    
      <a href="/2020/11/11/develop/%E6%8E%8C%E6%8F%A1%20Python%20%E7%9A%84%20Lambda%20%E5%87%BD%E6%95%B0/" class="article-nav-link">
        <strong class="article-nav-caption">上一篇</strong>
        <div class="article-nav-title">
          
            掌握 Python 的 Lambda 函数.md
          
        </div>
      </a>
    
    
      <a href="/2020/11/11/develop/%E7%94%A8Python%E6%93%8D%E4%BD%9CKubernetes%E7%9A%84Job/" class="article-nav-link">
        <strong class="article-nav-caption">下一篇</strong>
        <div class="article-nav-title">用Python操作Kubernetes的Job.md</div>
      </a>
    
  </nav>

   
<!-- valine评论 -->
<div id="vcomments-box">
  <div id="vcomments"></div>
</div>
<script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/valine@1.4.14/dist/Valine.min.js"></script>
<script>
  new Valine({
    el: "#vcomments",
    app_id: "",
    app_key: "",
    path: window.location.pathname,
    avatar: "monsterid",
    placeholder: "给我的文章加点评论吧~",
    recordIP: true,
  });
  const infoEle = document.querySelector("#vcomments .info");
  if (infoEle && infoEle.childNodes && infoEle.childNodes.length > 0) {
    infoEle.childNodes.forEach(function (item) {
      item.parentNode.removeChild(item);
    });
  }
</script>
<style>
  #vcomments-box {
    padding: 5px 30px;
  }

  @media screen and (max-width: 800px) {
    #vcomments-box {
      padding: 5px 0px;
    }
  }

  #vcomments-box #vcomments {
    background-color: #fff;
  }

  .v .vlist .vcard .vh {
    padding-right: 20px;
  }

  .v .vlist .vcard {
    padding-left: 10px;
  }
</style>

 
     
</article>

</section>
      <footer class="footer">
  <div class="outer">
    <ul>
      <li>
        Copyrights &copy;
        2015-2020
        <i class="ri-heart-fill heart_icon"></i> TzWind
      </li>
    </ul>
    <ul>
      <li>
        
        
        
        由 <a href="https://hexo.io" target="_blank">Hexo</a> 强力驱动
        <span class="division">|</span>
        主题 - <a href="https://github.com/Shen-Yu/hexo-theme-ayer" target="_blank">Ayer</a>
        
      </li>
    </ul>
    <ul>
      <li>
        
        
        <span>
  <span><i class="ri-user-3-fill"></i>访问人数:<span id="busuanzi_value_site_uv"></span></s>
  <span class="division">|</span>
  <span><i class="ri-eye-fill"></i>浏览次数:<span id="busuanzi_value_page_pv"></span></span>
</span>
        
      </li>
    </ul>
    <ul>
      
    </ul>
    <ul>
      
    </ul>
    <ul>
      <li>
        <!-- cnzz统计 -->
        
        <script type="text/javascript" src='https://s9.cnzz.com/z_stat.php?id=1278069914&amp;web_id=1278069914'></script>
        
      </li>
    </ul>
  </div>
</footer>
      <div class="float_btns">
        <div class="totop" id="totop">
  <i class="ri-arrow-up-line"></i>
</div>

<div class="todark" id="todark">
  <i class="ri-moon-line"></i>
</div>

      </div>
    </main>
    <aside class="sidebar on">
      <button class="navbar-toggle"></button>
<nav class="navbar">
  
  <div class="logo">
    <a href="/"><img src="/images/ayer-side.svg" alt="Hexo"></a>
  </div>
  
  <ul class="nav nav-main">
    
    <li class="nav-item">
      <a class="nav-item-link" href="/">主页</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/archives">归档</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/categories">分类</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags">标签</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" target="_blank" rel="noopener" href="http://www.baidu.com">百度</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/friends">友链</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/2019/about">关于我</a>
    </li>
    
  </ul>
</nav>
<nav class="navbar navbar-bottom">
  <ul class="nav">
    <li class="nav-item">
      
      <a class="nav-item-link nav-item-search"  title="搜索">
        <i class="ri-search-line"></i>
      </a>
      
      
      <a class="nav-item-link" target="_blank" href="/atom.xml" title="RSS Feed">
        <i class="ri-rss-line"></i>
      </a>
      
    </li>
  </ul>
</nav>
<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div>
    </aside>
    <script>
      if (window.matchMedia("(max-width: 768px)").matches) {
        document.querySelector('.content').classList.remove('on');
        document.querySelector('.sidebar').classList.remove('on');
      }
    </script>
    <div id="mask"></div>

<!-- #reward -->
<div id="reward">
  <span class="close"><i class="ri-close-line"></i></span>
  <p class="reward-p"><i class="ri-cup-line"></i>请我喝杯咖啡吧~</p>
  <div class="reward-box">
    
    
  </div>
</div>
    
<script src="/js/jquery-2.0.3.min.js"></script>


<script src="/js/lazyload.min.js"></script>

<!-- Tocbot -->


<script src="/js/tocbot.min.js"></script>

<script>
  tocbot.init({
    tocSelector: '.tocbot',
    contentSelector: '.article-entry',
    headingSelector: 'h1, h2, h3, h4, h5, h6',
    hasInnerContainers: true,
    scrollSmooth: true,
    scrollContainer: 'main',
    positionFixedSelector: '.tocbot',
    positionFixedClass: 'is-position-fixed',
    fixedSidebarOffset: 'auto'
  });
</script>

<script src="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.css">
<script src="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/js/jquery.justifiedGallery.min.js"></script>

<script src="/dist/main.js"></script>

<!-- ImageViewer -->

<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>

    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">

        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                <!--  Controls are self-explanatory. Order can be changed. -->

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" style="display:none" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                        <div class="pswp__preloader__cut">
                            <div class="pswp__preloader__donut"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div>
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/default-skin/default-skin.min.css">
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe-ui-default.min.js"></script>

<script>
    function viewer_init() {
        let pswpElement = document.querySelectorAll('.pswp')[0];
        let $imgArr = document.querySelectorAll(('.article-entry img:not(.reward-img)'))

        $imgArr.forEach(($em, i) => {
            $em.onclick = () => {
                // slider展开状态
                // todo: 这样不好，后面改成状态
                if (document.querySelector('.left-col.show')) return
                let items = []
                $imgArr.forEach(($em2, i2) => {
                    let img = $em2.getAttribute('data-idx', i2)
                    let src = $em2.getAttribute('data-target') || $em2.getAttribute('src')
                    let title = $em2.getAttribute('alt')
                    // 获得原图尺寸
                    const image = new Image()
                    image.src = src
                    items.push({
                        src: src,
                        w: image.width || $em2.width,
                        h: image.height || $em2.height,
                        title: title
                    })
                })
                var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, {
                    index: parseInt(i)
                });
                gallery.init()
            }
        })
    }
    viewer_init()
</script>

<!-- MathJax -->

<!-- Katex -->

<!-- busuanzi  -->


<script src="/js/busuanzi-2.3.pure.min.js"></script>


<!-- ClickLove -->

<!-- ClickBoom1 -->

<!-- ClickBoom2 -->

<!-- CodeCopy -->


<link rel="stylesheet" href="/css/clipboard.css">

<script src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js"></script>
<script>
  function wait(callback, seconds) {
    var timelag = null;
    timelag = window.setTimeout(callback, seconds);
  }
  !function (e, t, a) {
    var initCopyCode = function(){
      var copyHtml = '';
      copyHtml += '<button class="btn-copy" data-clipboard-snippet="">';
      copyHtml += '<i class="ri-file-copy-2-line"></i><span>COPY</span>';
      copyHtml += '</button>';
      $(".highlight .code pre").before(copyHtml);
      $(".article pre code").before(copyHtml);
      var clipboard = new ClipboardJS('.btn-copy', {
        target: function(trigger) {
          return trigger.nextElementSibling;
        }
      });
      clipboard.on('success', function(e) {
        let $btn = $(e.trigger);
        $btn.addClass('copied');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-checkbox-circle-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPIED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-checkbox-circle-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
      clipboard.on('error', function(e) {
        e.clearSelection();
        let $btn = $(e.trigger);
        $btn.addClass('copy-failed');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-time-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPY FAILED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-time-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
    }
    initCopyCode();
  }(window, document);
</script>


<!-- CanvasBackground -->


    
  </div>
</body>

</html>